"""
 encoding    : utf-8
 @File       : submit_survey_page.py
 @Author     : Rao
 @Version    :
 @Description: 发布调查测试用例
 @Date       : 2024/06/15
"""
import time

import pytest
from selenium.common import NoSuchElementException

from common import OA_tools
from pages.public_infomation.submit_survey_page import SubmitSurveyAction


@pytest.mark.usefixtures('submit_survey_preset')
class TestSubmitSurvey:
    """测试用例"""

    def test_submit_survey_success(self, submit_survey_preset):
        """发布调查正向测试"""
        # 解析夹具返回的数据
        page, driver = submit_survey_preset
        # 打开页面
        page.tools.select(2, 3)

        # 从配置文件中获取测试数据
        datalist = OA_tools.QueryFile.yaml_data(
            OA_tools.QueryFile.find_path(
                file_name='submit_survey_test_data.yaml',
                start_dir='../../data')
        )['test_data_true']
        title = datalist['title']
        num = datalist['num']
        content = datalist['content']
        pro_name = datalist['pro_name']
        select_item = datalist['select_item']

        action = SubmitSurveyAction(page, driver)
        action.write_title(title)
        action.choose_category(num)
        action.choose_release_scope()
        action.write_content(content)
        action.add_project(pro_name, select_item)
        action.submit_survey()
        time.sleep(2)
        # 操作完成, 进行断言
        action.assert_right()
        # # 执行操作
        # try:
        #
        # except NoSuchElementException:
        #     pytest.skip('页面元素未找到,跳过此次测试用例')

    @pytest.mark.parametrize(
        argnames="title, num, content, pro_name, select_item",
        argvalues=[
            (data['title'], data['num'], data['content'], data['pro_name'], data['select_item'])
            for data in OA_tools.QueryFile.yaml_data(
                OA_tools.QueryFile.find_path(
                    file_name='submit_survey_test_data.yaml',
                    start_dir='../../data')
            )['test_data_false']
        ]
    )
    def test_submit_survey_failure(self, title, num, content, pro_name, select_item, submit_survey_preset):
        """发布调查反向验证"""
        # 解析夹具返回的数据
        page, driver = submit_survey_preset
        # 打开页面
        page.tools.select(2, 3)
        # 执行操作
        action = SubmitSurveyAction(page, driver)
        action.write_title(title)
        action.choose_category(num)
        action.choose_release_scope()
        action.write_content(content)
        action.add_project(pro_name, select_item)
        action.submit_survey()
        time.sleep(2)
        # 操作完成, 进行断言
        action.assert_fail()
        # try:
        #
        # except NoSuchElementException:
        #     pytest.skip('页面元素未找到,跳过此次测试用例')


if __name__ == '__main__':
    pytest.main()
